package com.interagriculture.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.interagriculture.common.PageResult;
import com.interagriculture.entity.Honor;
import com.interagriculture.mapper.HonorMapper;
import com.interagriculture.service.HonorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HonorServiceImpl implements HonorService {

    @Autowired
    private HonorMapper honorMapper;
    /**
     * 分页获取荣誉奖项,并且分页展示
     */
    public PageResult getHonors(Honor honor,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Honor> honorList = honorMapper.pageQuery(honor);
        Page<Honor> page = (Page<Honor>) honorList;
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 荣誉的增与改
     * @param honor
     */
    @Override
    public void saveOrUpdateInfo(Honor honor) {
        //判断有无id的数据,有就为修改,无就为新增
        if(honor.getId() == null){
            honorMapper.insert(honor);
        }else{
            honorMapper.update(honor);
        }
    }

    /**
     * 荣誉信息的删除
     * @param id
     */
    @Override
    public void delete(Integer id) {
        honorMapper.delete(id);
    }
}
